package cn.itcast.search.listener;

import cn.itcast.search.constants.MqConstant;
import cn.itcast.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MqListener {

    @Autowired
    private SearchService searchService;

    /**
     * 监听新增或修改商品
     * @param id
     */
    @RabbitListener(queues = MqConstant.ITEM_INSERT_QUEUE)
    public void insert(Long id) {
        log.info("接收到消息：" + id);
        searchService.insertDoc(id);
        log.info("新增或修改商品文档成功 商品id:{}", id);
    }

    /**
     * 监听删除商品
     * @param id
     */
    @RabbitListener(queues = MqConstant.ITEM_DELETE_QUEUE)
    public void delete(Long id) {
        log.info("接收到消息：" + id);
        searchService.deleteDoc(id);
        log.info("删除商品文档成功 商品id:{}", id);
    }

}
